package restless.utilities.testing {
	import flash.display.Sprite;
	
	import flash.display.*;
	import flash.display3D.VertexBuffer3D;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.geom.Vector3D;
	import flash.utils.*;
	import flash.text.*;
	import flash.system.System;

	/**
	 * ...
	 * @author Jordan Laine
	 */
	
	public class hitTestPointSpeedTest extends Sprite {
		
		private var __logger:TextField = new TextField();
		private var s:String = "";
		private var bd:BitmapData = new BitmapData(5, 5, false);
		
		private var rect:Rectangle = new Rectangle(0, 0, 5, 5);
		private var point:Point = new Point(20, 2);	
		private var r2:Rectangle = new Rectangle(point.x, point.y);
		private var p2:Point = new Point();
		private var vect3:Vector3D = new Vector3D(2, 2);
		
		
		private function row(...cols): void {
			__logger.appendText(cols.join(", ") + "\n");
		}
		
		public function hitTestV3(point:Vector3D):Boolean {
			return insideOfRect(new Rectangle(point.x, point.y, 1, 1));
		}
		
		public function insideOfRect(r:Rectangle):Boolean {
			var bool:Boolean;
			
			if (rect.right < r.left || rect.left > r.right ||
			rect.top > r.bottom || rect.bottom < r.top ) {
				bool = false;
			} else {
				bool = true;
			}
			
			//trace("inside of rectangle " + bool);
			return bool;
		}
		
		public function hitTestBitmap(p:Point):Boolean {
			return bd.hitTest(p2, 255, p);
		}
		
		public function hitTestPointSpeedTest() {
			
			__logger.autoSize = TextFieldAutoSize.LEFT;
			addChild(__logger);
			
			var n:Number;
			var i:int = 0;
			var beforeTime:int;
			var afterTime:int;
			var castTime:int;
			//var i:uint;
			var len:uint = 10000;
			trace("itterations: " + len);
			
			
			beforeTime = getTimer();
			for (i = 0; i < len; ++i) {
				insideOfRect(r2);
				
			}
			afterTime = getTimer();
			castTime = afterTime - beforeTime;
			row("v3d rect hittest ", castTime);
			
			beforeTime = getTimer();
			for (i = 0; i < len; ++i) {
				bd.fillRect(rect, 555555);
				hitTestBitmap(point);
			}
			afterTime = getTimer();
			castTime = afterTime - beforeTime;
			row("bitmap hittest ", castTime);
			
			
			
		}
	}
}
